Skip to content

feat(auth): user-scoped tenant discovery for tenant switchers (ADR-0011) - #21

Merged
swimmesberger merged 1 commit into
wt/watchtower-public-api-1f5a0efrom
wt/tenant-switcher
Aug 10, 2026
Merged

feat(auth): user-scoped tenant discovery for tenant switchers (ADR-0011)#21
swimmesberger merged 1 commit into
wt/watchtower-public-api-1f5a0efrom
wt/tenant-switcher

Conversation

@swimmesberger

Copy link
Copy Markdown
Owner

Stacked on #19 — merge that first, then this (base is its branch so the diff stays scoped).

What

Two endpoints answering which sibling tenants may the proven visiting user reach, powering an in-product tenant switcher with Watchtower as the identity provider for the apps it proxies:

  • GET /api/app/tenants/accessible — for the product UI itself (a tenant stack): accessible siblings of its own template as slug + domain, the caller marked current when it appears.
  • GET /api/mgmt/templates/{id}/tenants/accessible — the same user-filtered view for a granted management stack (its unfiltered operations list is unchanged).

How the user is proven

The caller forwards the visitor's X-Watchtower-Jwt (already delivered on every proxied request) alongside its own wtapp_ token. A new audience-validating AuthTokenSigner overload requires the JWT's aud to match one of the calling stack's own route domains (custom AudienceValidator, case-insensitive; empty set fails closed) — so an app can only ask about users actively visiting it, and a JWT leaked to another app is inert. The user row is then re-read, refusing disabled accounts within the 5-minute token window. Every assertion failure yields one uniform 401.

Access per sibling follows the central-auth policy on its primary route — Public/Authenticated pass, Restricted needs a RouteAccessGrant, unknown modes fail closed — via a new bulk RouteAccessPolicy.AccessibleRouteIdsAsync (one grants query per template).

Reviewer notes

  • ADR-0011 records this as the single scoped amendment to ADR-0008's "a stack can only ever see itself"; ADR-0008/0009 gained pointers.
  • The slug accessible is now reserved at provisioning — it would collide with the literal route segment.
  • Both endpoints are 404 when central auth is off (UserInfo precedent).
  • The caller's own row is honestly filtered like any sibling, so current may be absent — documented.
  • 31 new tests: wrong-audience, alg-confusion-carrying-correct-aud, routeless caller, disabled user, fail-closed unknown mode, uniform-401 body equality, cross-template isolation.

Verification

dotnet build Release 0 warnings · 355 tests green · no rpc-schema.json drift · npm run build clean.

A tenant stack (and a granted management stack) can now ask which sibling
tenants the proven visiting user may reach, powering an in-product tenant
switcher with Watchtower as the identity provider.

- GET /api/app/tenants/accessible — siblings of the caller's own template
  the user may enter (slug + domain, caller marked current when present).
- GET /api/mgmt/templates/{id}/tenants/accessible — the same user-filtered
  view for a granted management stack; the unfiltered list is unchanged.
- Proof of user is the forwarded X-Watchtower-Jwt assertion: a new
  audience-validating AuthTokenSigner overload requires aud to match one of
  the CALLING stack's own route domains (case-insensitive via a custom
  AudienceValidator; empty set fails closed), then the user row is reloaded
  so disabled accounts are refused within the token window. One uniform 401
  for every assertion failure.
- RouteAccessPolicy.AccessibleRouteIdsAsync: bulk per-template access
  evaluation (Public/Authenticated pass, Restricted via one grants query,
  unknown modes fail closed).
- Slug 'accessible' reserved at provisioning (route-literal shadowing).
- Both endpoints 404 when central auth is off, per the UserInfo precedent.
- ADR-0011 records the scoped amendment of ADR-0008's self-only invariant;
  both public API docs updated; ADR-0008/0009 gained pointers.
- 31 new tests incl. wrong-audience, alg-confusion-with-correct-aud,
  routeless-caller, fail-closed unknown mode, and uniform-401 equality.
@swimmesberger
swimmesberger merged commit 5cecb4e into main Aug 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant